/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ClientServer;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Van Cong
 */
public class Client {
    public Socket socket;
    public DataInputStream diStream;
    public DataOutputStream doStream;
    public Client(){
        try {
            socket = new Socket("localhost", 2014);
            doStream = new DataOutputStream(socket.getOutputStream());
            diStream = new DataInputStream(socket.getInputStream());
            loop();
        } catch (IOException ex) {
            Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    public void loop(){
        try {
            String content = diStream.readUTF();
            System.out.println("Server say: "+content);
        } catch (IOException ex) {
            closeConnect();
        }
    }
    public void closeConnect(){
        try {
            doStream.close();
            diStream.close();
            socket.close();
        } catch (IOException ex) {
            Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public static void main(String[] args) {
        new Client();
    }
}
